package com.chaos.framework.model.dto.result;

import com.chaos.framework.model.dto.DTO;
import com.chaos.framework.model.enums.ResultEnum;
import com.chaos.framework.model.enums.ShowTypeEnums;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class Result extends DTO {

    private Integer code;

    private String msg;
    private Integer showType = ShowTypeEnums.DEFAULT.getCode();


    public static Result ok() {
        Result result = new Result();
        result.setCode(ResultEnum.OK.getCode());
        result.setMsg(ResultEnum.OK.getMsg());
        return result;
    }

    public static Result error() {
        Result result = new Result();
        result.setCode(ResultEnum.INTERNAL_SERVER_ERROR.getCode());
        result.setMsg(ResultEnum.INTERNAL_SERVER_ERROR.getMsg());
        return result;
    }

    public static Result unknow() {
        Result result = new Result();
        result.setCode(ResultEnum.UNKNOWN_ERROR.getCode());
        result.setMsg(ResultEnum.UNKNOWN_ERROR.getMsg());
        return result;
    }


    public static Result of(Integer code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static Result of(ResultEnum re) {
        Result result = new Result();
        result.setCode(re.getCode());
        result.setMsg(re.getMsg());
        return result;

    }

    public boolean isSuccess() {
        return ResultEnum.OK.getCode().intValue() == this.getCode().intValue();
    }


}
